2aae848f65cbd55d7cc09302bd219118174d9da5,geoserver/webapp/src/main/java/com/boundlessgeo/geoserver/api/controllers/ImportController.java,ImportController,moveFile,#ImportTask#,254

Before Change


        
        //Special behavior for SpatialFile - linked files
        FileData srcData = (FileData)t.getData();
        File srcFile = srcData.getFile();
        File storeFile;
        
        File destDir;
        FileData destData;
        File destFile;
        
        try {
            destDir = uploadDir(catalog, ws, store);
            destFile = new File(destDir, srcData.getFile().getName());
            if (srcFile.getAbsoluteFile().equals(destFile.getAbsoluteFile())) {
                LOG.warning("Trying to move file to itself");
                return;
            }
            destDir.mkdirs();
            
            //Update Store
            File baseDirectory = catalog.getResourceLoader().getBaseDirectory();
            
            if (store instanceof CoverageStoreInfo) {
                storeFile = catalog.getResourceLoader().url(((CoverageStoreInfo)store).getURL());
                //A CoverageStore needs a single file
                String url = "file:"+Paths.convert(baseDirectory, destFile);
                if (!(srcData.getFile().getAbsolutePath().equals(storeFile.getAbsolutePath())) ) {
                    throw new RuntimeException("CoverageStore file not the same as imported file");
                }
                ((CoverageStoreInfo)store).setURL(url);
            } else if (store instanceof DataStoreInfo){
                storeFile = catalog.getResourceLoader().url(store.getConnectionParameters().get("url").toString());
                /* A DataStore may contain multiple files as separate "tables".
                 * Therefore, we use the store dir for the URL, and ensure the file location is 
                 * somewhere in this directory.
                 * * If the store file is the same as the destination directory, then we may be in 
                 *   progress moving files.
                 * * If the store file is a prefix of the source data file, then all is well
                 * * Otherwise, we have a problem and should abort.
                 */
                String url = "file:"+Paths.convert(baseDirectory, destDir);
                if (!(storeFile.equals(destDir.getAbsoluteFile()) 
                        || srcData.getFile().getAbsolutePath().startsWith(storeFile.getAbsolutePath())) ) {
                    throw new RuntimeException("DataStore file not the same as imported file");
                }
                store.getConnectionParameters().put("url", url);
            } else {
                throw new RuntimeException("Invalid store type: "+store.getClass());
            }
            //Test if we can actually move the file; otherwise copy the file.
            boolean move = srcFile.renameTo(srcFile);
            
            if (move) {
                Files.move(srcFile.toPath(), destFile.toPath());
            } else {
                Files.copy(srcFile.toPath(), destFile.toPath());
            }
            //move any supplementary files, update ImportData
            if (srcData instanceof SpatialFile) {
                destData = new SpatialFile(destFile);
                if (((SpatialFile)srcData).getPrjFile() != null) {
                    File prjFile = new File(destDir, ((SpatialFile)srcData).getPrjFile().getName());
                    if (move) {
                        Files.move(((SpatialFile)srcData).getPrjFile().toPath(), prjFile.toPath());
                    } else{
                        Files.copy(((SpatialFile)srcData).getPrjFile().toPath(), prjFile.toPath());
                    }
                    ((SpatialFile)destData).setPrjFile(prjFile);
                }

After Change


        
        //Special behavior for SpatialFile - linked files
        FileData srcData = (FileData)t.getData();
        File srcFile = srcData.getFile().file();
        File storeFile;
        
        File destDir;
        FileData destData;
        File destFile;
        
        try {
            destDir = uploadDir(catalog, ws, store);
            destFile = new File(destDir, srcData.getFile().file().getName());
            if (srcFile.getAbsoluteFile().equals(destFile.getAbsoluteFile())) {
                LOG.warning("Trying to move file to itself");
                return;
            }
            destDir.mkdirs();
            
            //Update Store
            File baseDirectory = catalog.getResourceLoader().getBaseDirectory();
            
            if (store instanceof CoverageStoreInfo) {
                storeFile = catalog.getResourceLoader().url(((CoverageStoreInfo)store).getURL());
                //A CoverageStore needs a single file
                String url = "file:"+Paths.convert(baseDirectory, destFile);
                if (!(srcData.getFile().file().getAbsolutePath().equals(storeFile.getAbsolutePath())) ) {
                    throw new RuntimeException("CoverageStore file not the same as imported file");
                }
                ((CoverageStoreInfo)store).setURL(url);
            } else if (store instanceof DataStoreInfo){
                storeFile = catalog.getResourceLoader().url(store.getConnectionParameters().get("url").toString());
                /* A DataStore may contain multiple files as separate "tables".
                 * Therefore, we use the store dir for the URL, and ensure the file location is 
                 * somewhere in this directory.
                 * * If the store file is the same as the destination directory, then we may be in 
                 *   progress moving files.
                 * * If the store file is a prefix of the source data file, then all is well
                 * * Otherwise, we have a problem and should abort.
                 */
                String url = "file:"+Paths.convert(baseDirectory, destDir);
                if (!(storeFile.equals(destDir.getAbsoluteFile()) 
                        || srcData.getFile().file().getAbsolutePath().startsWith(storeFile.getAbsolutePath())) ) {
                    throw new RuntimeException("DataStore file not the same as imported file");
                }
                store.getConnectionParameters().put("url", url);
            } else {
                throw new RuntimeException("Invalid store type: "+store.getClass());
            }
            //Test if we can actually move the file; otherwise copy the file.
            boolean move = srcFile.renameTo(srcFile);
            
            if (move) {
                Files.move(srcFile.toPath(), destFile.toPath());
            } else {
                Files.copy(srcFile.toPath(), destFile.toPath());
            }
            //move any supplementary files, update ImportData
            if (srcData instanceof SpatialFile) {
                destData = new SpatialFile(destFile);
                if (((SpatialFile)srcData).getPrjFile() != null) {
                    File prjFile = new File(destDir, ((SpatialFile)srcData).getPrjFile().file().getName());
                    if (move) {
                        Files.move(((SpatialFile)srcData).getPrjFile().file().toPath(), prjFile.toPath());
                    } else{
                        Files.copy(((SpatialFile)srcData).getPrjFile().file().toPath(), prjFile.toPath());
                    }
                    ((SpatialFile)destData).setPrjFile(org.geoserver.platform.resource.Files.asResource(prjFile));
                }